package com.aischool.eduorg.api;

import com.aischool.routes.RouteMapping;
import com.aischool.service.AiAppArticleCatService;
import com.aischool.service.AiArticlecatService;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;

@RouteMapping(url = "/api/eduorg/articlecat")
public class ArticleCatController extends BaseApiEduorgController {

	@Inject
	AiArticlecatService aiArticlecatService;
	@Inject
	AiAppArticleCatService aiAppArticleCatService;
	
	public void getAll() {
		// 结果类
		JsonResult jr = new JsonResult();
		int app_id = this.getAttrForInt("login_app_id");
		int org_id = this.getAttrForInt("login_org_id");
		int type_id = getInt("type_id", 0);
		int cat_state = getInt("state");
		
		if (type_id > 0) {
			Object obj = aiArticlecatService.getAll(type_id, cat_state);
			jr.setDicKV("listdata", obj);
			
			obj = aiAppArticleCatService.getAll(app_id, org_id, type_id);
			jr.setDicKV("listappcat", obj);
		}
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	
	public void save() {
		// 结果类
		JsonResult jr = new JsonResult();
		int app_id = this.getAttrForInt("login_app_id");
		int org_id = this.getAttrForInt("login_org_id");
		int type_id = getInt("type_id", 0);
		String ids = getPara("ids", "");
		
		if (app_id <= 0 || type_id <= 0) {
			jr.setCode(400);
			jr.setMsg("缺少参数！");
		}else {
			boolean bf = aiAppArticleCatService.updateAppArticleCat(app_id, org_id, type_id, ids);
			if (bf) {
				jr.setEnum(JsonCodeEnum.Success);
			}else {
				jr.setEnum(JsonCodeEnum.Faild);
			}
		}
		
		
		renderJson(jr.Dic);
		
	}
}
